package efg.library.EJB;




import java.util.HashMap;
import java.util.HashSet;

public class Book
{  
  /***************************************************************************\
   * Static
  \***************************************************************************/
  private static HashMap<String, Book> books = new HashMap<String, Book>();
  
  static
  {
    new Book("The Java Programming Language, Fourth Edition");
    new Book("Pro J2EE 1.4 From Professional to Expert");
    new Book("JavaServer Faces in Action");
    new Book("jQuery in Action");
  }
   
  static Book findBook(String title)
  {
    synchronized (books)
    {
      return books.get(title);
    }
  }
  
  static void removeBook(String title)
  {
    synchronized (books)
    {
      books.remove(title);
    }
  }
  
  static HashSet<Book> allBooks()
  {
    HashSet<Book> ret = new HashSet<Book>();
    synchronized (books)
    {
      for (String title: books.keySet())
      {
        ret.add(books.get(title));
      }
    }
    return ret;
  }
  
  /***************************************************************************\
   * Object
  \***************************************************************************/  
  private String title = null;
  private Customer lendTo = null;
  
  Book(String newTitle)
  {
    title = newTitle;
    synchronized (books)
    {
      books.put(title, this);
    }
  }
  
  public String getTitle()
  {
     return title;
  }
  
  Customer getLendTo()
  {
    return lendTo;
  }
  
  void setLendTo(Customer customer)
  {
    lendTo = customer;
  }
  
  @Override
  public String toString()
  {
    return "book"; //"[Book: "+title+" "+lendTo.getName()+"]";
  } 
}
